package com.ruoyi.utils;

import com.ruoyi.app.domain.vo.UserLoginVO;

public class ApiThreadUtils {

    private static final ThreadLocal<UserLoginVO> USER_CONTEXT = new InheritableThreadLocal<>();

    private static final ThreadLocal<Long> REQUEST_COST_CONTEXT = new InheritableThreadLocal<>();

    private ApiThreadUtils() {
    }

    public static void setUser(UserLoginVO user) {
        USER_CONTEXT.set(user);
    }

    public static UserLoginVO getUser() {
        return USER_CONTEXT.get();
    }

    public static void removeUser() {
        USER_CONTEXT.remove();
    }

    public static void setRequestStartTime(Long startTime) {
        REQUEST_COST_CONTEXT.set(startTime);
    }

    public static void removeRequestStartTime() {
        REQUEST_COST_CONTEXT.remove();
    }

    public static Long getRequestStartTime() {
        return REQUEST_COST_CONTEXT.get();
    }
}
